<!DOCTYPE html>
<html>
<head>
<title>req_assign</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" type="text/css"
	href="/codebase/fonts/font_roboto/roboto.css" />
<link rel="stylesheet" type="text/css" href="/codebase/dhtmlx.css" />
<script type="text/javascript" src="/codebase/dhtmlxform.js" />
<script type="text/javascript" src="/codebase/dhtmlxgrid.js" />
<script type="text/javascript" src="/codebase/dhtmlxeditor.js" />  
<style>
</style>
<script>
/*<![CDATA[*/
	var myForm, myGrid;
	function doOnLoad() {
		var v=document.getElementById("assign_test_id").innerHTML;
		//alert("onload req assign");
		eXcell_button_edit.prototype = new eXcell;
		eXcell_button_del.prototype = new eXcell;
		
		//grid setup
		if (myGrid) {
			myGrid.clearAll(true);
		}
		myGrid = new dhtmlXGridObject("grid_team_list");
		//myGrid.loadStruct("/common/testmanager/req_list.xml");
		myGrid.setImagePath("/codebase/imgs/");

		myGrid.setHeader("Log ID,姓名,填报日期,工作日志,,");
		myGrid.setInitWidths("50,50,100,300,70,70");
		myGrid.setColAlign("center,left,left,left,center,center");
		myGrid.setColTypes("ro,ro,ro,ro,button_edit,button_del");
		myGrid.setColSorting("str,str,str,str,str,str");
		//myGrid.setColumnIds("first,second");
		myGrid.xml.top = "mytop";
		myGrid.xml.row = "./myrow";
		//myGrid.enableAutoWidth(true);
		//myGrid.enableAutoHeight(true);
		myGrid.init();
		myGrid.load("/test/test_modify_detail_work_log_info_grid?test_id="+v,"json");
		/* myGrid.attachEvent("onRowSelect",function(rowID,celInd){
		    //alert("The id of the selected row is "+rowID);		    
		    myGrid.cells(rowID,0).setValue("1");
		    
		}); */
		
		if (myForm) {
			myForm.unload();
			myForm = null;
		}
		myForm=new dhtmlXForm("form_req_base_info");
		//myForm.loadStruct(formStructure);
		myForm.loadStruct("/test/test_modify_detail_work_log_info_onload?test_id="+v);
		
		myForm.attachEvent("onButtonClick", function(name) {
			if (name == "save_btn") {
				//myForm.save("/req/req_modify_detail_work_log_info_save");	
				var get_user_name=myForm.getItemValue("user_name");
				//var get_work_date=myForm.getItemValue("work_date");
				var dhxCalendar = myForm.getCalendar("work_date");
				var get_work_date=dhxCalendar.getDate(true);
				//var d = new Date(get_work_date);
				//get_work_date=d.getFullYear() + '-' + (d.getMonth() + 1) + '-' + d.getDate();
				
				var is_new=false;
				is_new=check_worklog_is_input(get_user_name,get_work_date);
				var get_is_edit = myForm.getItemValue("is_edit");
				if(get_is_edit=="yes"){
					is_new=false;
					myForm.setItemValue("is_edit","");
				}		
				if(is_new){
					alert("当前用户["+get_user_name+"]在["+get_work_date+"]录入过工作日志，请选择编辑");
				}else{					
					this.send("/test/test_modify_detail_work_log_info_save",callback);	
				}
				
			}
			if (name == "modify_btn") {
				//myForm.save("/req/req_modify_detail_work_log_info_save");		
				var get_row=myGrid.getCheckedRows(0);
				var get_user_name=myGrid.cells(get_row,2).getValue();
				var get_work_date=myGrid.cells(get_row,3).getValue();
				var get_work_log=myGrid.cells(get_row,4).getValue();					
				myForm.setItemValue("user_name", get_user_name);
				myForm.setItemValue("work_date", get_work_date);				
				myForm.setItemValue("work_log", get_work_log);
				//alert("编辑区已加载，请修改后点击保存按钮");
				//this.send("/req/req_modify_detail_work_log_info_save",callback);
			}
			if (name == "del_btn") {
				var get_row=myGrid.getCheckedRows(0);
				var v=document.getElementById("assign_test_id").innerHTML;
				myGrid.clearAndLoad("/test/test_modify_detail_work_log_info_grid_delete?id="+get_row+"&test_id="+v,"json");			
				
			}
		});
}
	
	var callback=function () {
		//alert("callback");
		
		if(arguments[1]=="true"){
			alert("保存需求成功");	
			//myForm.clear();
			myForm.setItemValue("user_name", "");
			myForm.setItemValue("work_date", "");
			myForm.setItemValue("work_log", "");
			var v=document.getElementById("assign_test_id").innerHTML;
			myGrid.clearAndLoad("/test/test_modify_detail_work_log_info_grid?test_id="+v,"json");	
		}
		else{
			alert("保存需求失败，错误信息："+arguments[1]);
		}
	}
	
	
	function check_worklog_is_input(user_name,work_date){
		var result=false;
		for (var j=1; j<(myGrid.getRowsNum()+1); j++){		
			var tmp_name=myGrid.cells(j,1).getValue();	
			//alert(tmp_name);
			if(tmp_name==user_name){				
				var tmp_work_date=myGrid.cells(j,2).getValue();	
				if(tmp_work_date==work_date){
					//alert(tmp_work_date);
					result=true;
				}				
			}
		}
		return result;
	}
	
	function edit(get_row){
		//var get_row=myGrid.getCheckedRows(0);
		var get_user_name=myGrid.cells(get_row,1).getValue();
		var get_work_date=myGrid.cells(get_row,2).getValue();
		var get_work_log=myGrid.cells(get_row,3).getValue();					
		myForm.setItemValue("user_name", get_user_name);
		myForm.setItemValue("work_date", get_work_date);
		//myForm.setItemValue("work_log", get_work_log);
		var get_editor=myForm.getEditor("work_log");
		var log_id=myGrid.cells(get_row,0).getValue();
		get_editor.setContentHTML("/test/get_worklog_content?log_id="+log_id);
		
		myForm.setItemValue("is_edit","yes");
	}
	
	function del(get_row){
	//var get_row=myGrid.getCheckedRows(0);
		 if(confirm("你确定要提交？"))					 
				    {
	var log_id=myGrid.cells(get_row,0).getValue();
	var v=document.getElementById("assign_test_id").innerHTML;
	myGrid.clearAndLoad("/test/test_modify_detail_work_log_info_grid_delete?id="+log_id+"&test_id="+v,"json");
				    }
	}
	
	function eXcell_button_edit(cell){ //the eXcell name is defined here
	    if (cell){                // the default pattern, just copy it
	        this.cell = cell;
	        this.grid = this.cell.parentNode.grid;
	    }
	    this.edit = function(){}  //read-only cell doesn't have edit method
	    // the cell is read-only, so it's always in the disabled state
	    this.isDisabled = function(){ return true; }
	    this.setValue=function(val){
	    	var row_id=this.cell.parentNode.idd;
	        this.setCValue("<input type='button' onclick='edit("+row_id+")' value='编辑'>",val);                                      
	    }
	}
	
	function eXcell_button_del(cell){ //the eXcell name is defined here
	    if (cell){                // the default pattern, just copy it
	        this.cell = cell;
	        this.grid = this.cell.parentNode.grid;
	    }
	    this.edit = function(){}  //read-only cell doesn't have edit method
	    // the cell is read-only, so it's always in the disabled state
	    this.isDisabled = function(){ return true; }
	    this.setValue=function(val){
	    	var row_id=this.cell.parentNode.idd;
	        this.setCValue("<input type='button' onclick='del("+row_id+")' value='删除'>",val);                                      
	    }
	}	
/*]]>*/	
</script>
</head>
<body onload="doOnLoad();">
<div id="assign_test_id" name="assign_test_id" th:text="${test_id}" style="display: none;" > </div>
	<table>
		<tr>
			<td>
				<div id="form_req_base_info"></div>
			</td>
		</tr>
		<tr>
			<td>

				<div id="grid_team_list"
					style="width: 700px; height: 200px; background-color: white;">
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="div_count_form"></div>
			</td>
		</tr>
	</table>


</body>
</html>